package com.fifth.commodity.controller;

import com.fifth.commodity.vo.GoodsVo;
import com.fifth.commodity.vo.QianGetGoodsVo;
import com.fifth.commodity.vo.StateVo;
import com.fifth.commodity.vo.StatusVo;
import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.commodity.service.GoodsService;
import com.fifth.common.pojo.entity.Goods;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商品相关接口")
@RestController
@RequestMapping("/commodity/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 查询所有商品包含分页和条件
     * @param pageCurrent
     * @param pageSize
     * @param goodsVo
     * @return
     */
    @ApiOperation(value = "根据条件分页查询所有商品")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name = "pageCurrent",value = "页码数"),
            @ApiImplicitParam(dataType = "int",name = "pageSize",value = "每页显示个数"),
            @ApiImplicitParam(dataType = "GoodsVo",name = "goodsVo",value = "查询条件"),
    })
    @PostMapping("findAllGoods/{pageCurrent}/{pageSize}")
    public CommonResult findAllGoods(@PathVariable Integer pageCurrent,@PathVariable Integer pageSize,@RequestBody GoodsVo goodsVo){
    return goodsService.findAllGoods(pageCurrent,pageSize,goodsVo);
    }

    /**
     * 根据id和state修改商品上下架状态
     * @param statusVo
     * @return
     */
    @ApiOperation(value = "根据id和status修改商品上下架状态")
    @ApiImplicitParam(dataType = "StatusVo",name = "statusVo",value = "修改状态的实体类")
    @PostMapping("updateStatus")
    public CommonResult updateStatus(@RequestBody StatusVo statusVo){
        return goodsService.upadteStatus(statusVo);
    }

    /**
     * 修改商品审核状态
     * @param stateVo
     * @return
     */
    @ApiOperation(value = "修改商品的审核状态")
    @PostMapping("updateState")
    @ApiImplicitParam(dataType = "StateVo",name = "stateVo",value = "修改审核状态的实体类")
    public CommonResult updateState(@RequestBody StateVo stateVo){
        return goodsService.updateState(stateVo);
    }

    /**
     * 根据goodsid查询商品信息
     * @param id
     * @return
     */
    @ApiOperation("根据goodsid查询商品信息")
    @ApiImplicitParam(dataType = "String",name = "id",value = "商品id")
    @PostMapping("findGoodsByGoodsid/{id}")
    public CommonResult findGoodsByGoodsid(@PathVariable String id){
        return goodsService.findGoodsByGoodsid(id);
    }

    /**
     * 根据goodsid查询成交量
     * @param goodsid
     * @return
     */
    @ApiOperation("根据goodsid查询成交量")
    @ApiImplicitParam(dataType = "String",name = "goodsid",value = "商品id")
    @PostMapping("getGoodsSellNum/{goodsid}")
    public CommonResult getGoodsSellNum(@PathVariable String goodsid){
        return goodsService.getGoodsSellNum(goodsid);
    }

    /**
     * 根据goodsid判断当前用户是否收藏该商品
     * @param id
     * @return
     */
    @PostMapping("isGoodsCollection/{id}")
    public CommonResult isGoodsCollection(@PathVariable String id){
        return goodsService.isGoodsCollection(id);
    }

    /**
     * 修改收藏状态
     * @param id
     * @return
     */
    @ApiOperation("修改收藏状态")
    @ApiImplicitParam(dataType = "String",name = "id",value = "商品id")
    @PostMapping("changeCollectionStatus/{id}/{status}")
    public CommonResult changeCollectionStatus(@PathVariable String id,@PathVariable Integer status){
        return goodsService.changeCollectionStatus(id,status);
    }

    /**
     * 根据bid判断当前用户是否关注该店铺
     * @param bid
     * @return
     */
    @ApiOperation("判断当前用户是否关注该店铺")
    @ApiImplicitParam(dataType = "String",name = "bid",value = "店铺id")
    @PostMapping("isCollectionBusiness/{bid}")
    public CommonResult isCollectionBusiness(@PathVariable String bid){
        return goodsService.isCollectionBusiness(bid);
    }

    /**
     * 点击关注/取关
     * @param bid
     * @param status
     * @return
     */
    @ApiOperation("关注/去关店铺")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String",name = "bid",value = "店铺id"),
            @ApiImplicitParam(dataType = "int",name = "status",value = "状态码,0代表当前已关注/1代表当前未关注"),
    })
    @PostMapping("changeGuanzhu/{bid}/{status}")
    public CommonResult changeGuanzhu(@PathVariable String bid,@PathVariable Integer status){
        return goodsService.changeGuanzhu(bid,status);
    }

    /**
     * 根据id获取所有收获地址
     * @return
     */
    @ApiOperation("根据id获取所有收获地址")
    @PostMapping("getAllAddr")
    public CommonResult getAllAddr(){
        return goodsService.getAllAddr();
    }

    /**
     * 根据店铺id获取所有商品信息分页+条件
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name = "currentPage",value = "页码数"),
            @ApiImplicitParam(dataType = "int",name = "pageSize",value = "每页显示个数"),
            @ApiImplicitParam(dataType = "QianGetGoodsVo",name = "goodsVo",value = "查询条件"),
    })
    @PostMapping("selectAllGoodsInfoByBusinessId/{currentPage}/{pageSize}")
    public CommonResult selectAllGoodsInfoByBusinessId(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody QianGetGoodsVo goodsVo){
        return goodsService.selectAllGoodsInfoByBusinessId(currentPage,pageSize,goodsVo);
    }

    /**
     * 根据id删除商品
     * @param id
     * @return
     */
    @ApiOperation("根据id删除商品")
    @ApiImplicitParam(dataType = "String",name = "id",value = "商品id")
    @PostMapping("deleteGoodsById")
    public CommonResult deleteGoodsById(String id){
        return goodsService.deleteGoodsById(id);
    }

    /**
     * 添加商品
     * @param goods
     * @return
     */
    @PostMapping("addGoods")
    public CommonResult addGoods(@RequestBody Goods goods){
        return goodsService.addGoods(goods);
    }

    @ApiOperation("根据店铺id查询所有商品及店铺信息(前端调用)")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name = "pageCurrent",value = "页码数"),
            @ApiImplicitParam(dataType = "int",name = "pageSize",value = "每页显示个数"),
            @ApiImplicitParam(dataType = "String",name = "bid",value = "店铺id")
    })
    @GetMapping("/findGoodsByBid/{pageCurrent}/{pageSize}/{bid}")
    public CommonResult findGoodsByBid(@PathVariable Integer pageCurrent,@PathVariable Integer pageSize,@PathVariable String bid){
        return goodsService.findGoodsByBid(pageCurrent,pageSize,bid);
    }
    /**
     * 修改商品
     * @param goods
     * @return
     */
    @PostMapping("updateGoods")
    public CommonResult updateGoods(@RequestBody Goods goods){
        return goodsService.updateGoods(goods);
    }

    /**
     * 获取店铺类别
     * @return
     */
    @PostMapping("getSort")
    public CommonResult getSort(){
        return goodsService.getgetSort();
    }
}
